// toast弹窗
let timeOutId;
export const toast = function (msg, duration, moreclass) {
  let toastEle = document.getElementsByClassName('toast');
  if (toastEle.length > 0) {
    toastEle[0].innerHTML = "<div style='padding:5px 15px;font-size: 14px;color:#fff;text-align:center;word-break: break-all;background:rgba(0,0,0,.5);border-radius:30px;'>" + msg + '</div>';
  } else {
    toastEle = document.createElement('div');
    toastEle.className = 'modal toast' + (moreclass || '');
    toastEle.style.cssText = 'box-sizing:border-box;position: fixed;left: 50%;top: 50%;transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);-moz-transform:translate(-50%,-50%);-webkit-transform:translate(-50%,-50%);-o-transform:translate(-50%,-50%);padding:0 15px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;width:100%;background-color:transparent;z-index:999;';
    toastEle.innerHTML = "<div style='padding:5px 15px;font-size: 14px;color:#fff;text-align:center;word-break: break-all;background:rgba(0,0,0,.5);border-radius:30px;'>" + msg + '</div>';
    document.body.appendChild(toastEle);
  }
  if (timeOutId) {
    clearTimeout(timeOutId);
  }
  timeOutId = setTimeout(function () {
    toastEle = document.getElementsByClassName('toast');
    if (toastEle.length > 0) {
      document.body.removeChild(toastEle[0]);
    }
  }, 2000 || duration);
};